/**
 * @Description MyCouponController.java
 * @author xu_cc [18724000100@163.com]
 * @date 创建时间：2017年12月4日 上午9:56:18
 */
package com.solution.pc.my.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.solution.admin.coupon.constants.CouponConstants.IsUsed;
import com.solution.admin.coupon.service.CouponGetService;
import com.solution.admin.point.constants.PointConstants.IsYesNo;
import com.solution.common.controller.BaseController;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;

@RequestMapping("/pc/my")
@Controller("myCouponController")
public class MyCouponController extends BaseController {

	@Autowired
	CouponGetService couponGetService;

	/**
	 * 未使用
	 * 
	 * @param request
	 * @param model
	 * @return String
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年12月4日 下午4:32:50
	 */
	@RequestMapping("/couponGet")
	public String toCouponGetPage(HttpServletRequest request, Model model) {
		try {
			PageParam pageParam = super.getPageParam(request, 8);
			Map<String, Object> param = new HashMap<String, Object>();
			// 根据客户id查询优惠券
			param.put("customerId", getCustomerId());
			param.put("isExp", IsYesNo.NO);// 未过期
			param.put("isUsed", IsUsed.UN_USED);
			/* 未使用优惠券 */
			PageBean pageBean = couponGetService.listCouponGetPage(pageParam, param);
			model.addAttribute("couponGetList", pageBean.getRecordList());
			model.addAttribute("pageBean", pageBean);
		} catch (Exception e) {
			e.printStackTrace();
		}
		model.addAttribute("page", "coupon");
		model.addAttribute("tab", "coupon_get");
		return "pc/my/coupon/coupon_get";
	}

	/**
	 * 已过期
	 * 
	 * @param request
	 * @param model
	 * @return String
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年12月4日 下午4:32:50
	 */
	@RequestMapping("/couponExp")
	public String toCouponExpPage(HttpServletRequest request, Model model) {
		try {
			PageParam pageParam = super.getPageParam(request, 8);
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("customerId", getCustomerId());
			param.put("isUsed", IsUsed.UN_USED);
			param.put("isExp", IsYesNo.YES); // 已过期
			PageBean pageBean = couponGetService.listCouponGetPage(pageParam, param);
			model.addAttribute("couponExpList", pageBean.getRecordList());
			model.addAttribute("pageBean", pageBean);
		} catch (Exception e) {
			e.printStackTrace();
		}
		model.addAttribute("page", "coupon");
		model.addAttribute("tab", "coupon_exp");
		return "pc/my/coupon/coupon_exp";
	}

	/**
	 * 已使用
	 * 
	 * @param request
	 * @param model
	 * @return String
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2017年12月4日 下午4:32:50
	 */
	@RequestMapping("/couponUsed")
	public String toCouponUsedPage(HttpServletRequest request, Model model) {
		try {
			PageParam pageParam = super.getPageParam(request, 8);
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("customerId", getCustomerId());
			param.put("isUsed", IsUsed.USED);
			/* 已使用优惠券 */
			PageBean pageBean = couponGetService.listCouponGetPage(pageParam, param);
			// PageBean pageBean = couponUsedService.listCouponUsedPage(pageParam, param);
			model.addAttribute("couponUsedList", pageBean.getRecordList());
			model.addAttribute("pageBean", pageBean);
		} catch (Exception e) {
			e.printStackTrace();
		}
		model.addAttribute("page", "coupon");
		model.addAttribute("tab", "coupon_used");
		return "pc/my/coupon/coupon_used";
	}

}
